<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
</head>
<body>
    <form action="#">
        <h1>注册</h1>
        <div>
            <label for="phone">手机号</label>
            <input id="phone" type="text">
        </div>
        <div>
            <label for="pwd">密码</label>
            <input id="pwd" type="password">
        </div>
        <div>
            <label for="confirm">确认密码</label>
            <input id="confirm" type="password">
        </div>
        <!-- <button type="button">提交</button> -->
        <input type="submit">
    </form>
    <script>
        let phone = document.getElementById("phone");
        let pwd = document.getElementById("pwd");
        document.forms[0].onsubmit = function(e){
            e.preventDefault();
            let users = sessionStorage.getItem("users");
            if(!users){
                users = [];
            }else{
                users = JSON.parse(users);
            }
            users.push({
                phone:phone.value,
                pwd:pwd.value
            });
            sessionStorage.setItem("users",JSON.stringify(users));
            alert("注册成功");
            location.href = "login.html";
        }
    </script>
</body>
</html>